package com.ruoyi.erecord.locus.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.erecord.locus.domain.bo.LocusStateBo;
import com.ruoyi.erecord.locus.domain.vo.LocusStateVo;
import com.ruoyi.erecord.locus.service.ILocusStateService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 轨迹-人员状态
 *
 * @author cc
 * @date 2023-05-15
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/erecord/locusState")
public class LocusStateController extends BaseController {

    private final ILocusStateService iLocusStateService;

    /**
     * 查询轨迹-人员状态列表
     */
    @SaCheckPermission("erecord:locus:list")
    @GetMapping("/list")
    public TableDataInfo<LocusStateVo> list(LocusStateBo bo, PageQuery pageQuery) {
        return iLocusStateService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出轨迹-人员状态列表
     */
    @SaCheckPermission("erecord:locus:export")
    @Log(title = "轨迹-人员状态", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(LocusStateBo bo, HttpServletResponse response) {
        List<LocusStateVo> list = iLocusStateService.queryList(bo);
        ExcelUtil.exportExcel(list, "轨迹-人员状态", LocusStateVo.class, response);
    }

    /**
     * 获取轨迹-人员状态详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("erecord:locus:query")
    @GetMapping("/{id}")
    public R<LocusStateVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iLocusStateService.queryById(id));
    }

    /**
     * 新增轨迹-人员状态
     */
    @SaCheckPermission("erecord:locus:add")
    @Log(title = "轨迹-人员状态", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody LocusStateBo bo) {
        return toAjax(iLocusStateService.insertByBo(bo));
    }

    /**
     * 修改轨迹-人员状态
     */
    @SaCheckPermission("erecord:locus:edit")
    @Log(title = "轨迹-人员状态", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody LocusStateBo bo) {
        return toAjax(iLocusStateService.updateByBo(bo));
    }

    /**
     * 删除轨迹-人员状态
     *
     * @param ids 主键串
     */
    @SaCheckPermission("erecord:locus:remove")
    @Log(title = "轨迹-人员状态", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iLocusStateService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
